<template>
	<view class="flex col-center row-between  ">
		<view class="flex col-center">
			<image src="/static/image/index/bianzu@2x.png" class="w50" mode="widthFix"></image>
			<view class="felx1 flex col-center">
				<u-notice-bar 
				class="w500" 
				mode="vertical" 
				:list="noticeNames"
				:volume-icon="false"
				color="#333"
				bg-color="none"
				:more-icon="false"
				@click="toNoticeDetail"></u-notice-bar>	
				
			</view>
		</view>
		<text class="moretxt text-nowrap" @click="toNoticePage">更多</text>
	</view>
</template>

<script>
	export default {
		// name:'',
		props:{
			from:{
				//from==1表示朋友圈公告
				type:Number,
				required:false
			}
		},
		data () {
			return {
				noticeList: [],
				noticeNames: [],
			}
		},
		mounted() {
			this.getData()
		},
		methods: {
			toNoticeDetail (index) {
				let id = this.noticeList[index].id
				if(this.from==1) {
					uni.navigateTo({
						url: '/pages/home/notice/detail?id='+id+'&from='+this.from
					})
				}else {
					uni.navigateTo({
						url: '/pages/home/notice/detail?id='+id
					})
				}
				
			},
			getData () {
				let api=''
				if(this.from==1) {
					api='article_list'
				} else {
					api='announce_list'
				}
				this.$api[api]().then(res => {
					this.noticeList = res.data.data
					this.noticeNames = res.data.data.map(item => item.name)
				})
			},
			toNoticePage () {
				if(this.from==1) {
					uni.navigateTo({
						url: '/pages/home/notice/index?from=1'
					})
				}else {
					uni.navigateTo({
						url: '/pages/home/notice/index'
					})
				}
				
			}
		}
	}
</script>

<style>
</style>
